from django.db import models
class ExamUser(models.Model):
    user_name = models.CharField(max_length=64,null=False,unique=True)
    full_name = models.CharField(max_length=64,null=True)
    is_teacher=models.BooleanField(default=False)
    def __unicode__(self):
        return self.user_name


class Exam(models.Model):
    title = models.CharField(max_length=50,null=False,unique=True)
    description = models.TextField(null=True)
    datecreated = models.DateTimeField(auto_now_add=True)
    deadline = models.DateTimeField(null=False)
    author = models.ForeignKey(ExamUser,null=False)
    enabled=models.BooleanField(default=True)
    def __unicode__(self):
        return self.title

class ExamQuestion(models.Model):
    question = models.CharField(max_length=120,null=False)
    exam_id=models.ForeignKey(Exam,null=False)
    weight = models.IntegerField(null=True)
    def __unicode__(self):
        return self.question

class ExamOption(models.Model):
    answer_option=models.CharField(max_length=120,null=False)
    is_correct=models.BooleanField(default=False)
    exam_question_id=models.ForeignKey(ExamQuestion,null=False)


class StudentExam(models.Model):
    student=models.ForeignKey(ExamUser,null=False)
    exam_id =models.ForeignKey(Exam,null=False)
    exam_grade=models.IntegerField(null=False)
    date_submitted= models.DateTimeField(auto_now_add=True)
    def __unicode__(self):
        return self.student

class StudentAnswer(models.Model):
    student=models.ForeignKey(ExamUser,null=False)
    question_id=models.ForeignKey(ExamQuestion,null=False)
    option_id=models.ForeignKey(ExamOption,null=False)
    #def __unicode__(self):
     #   return self.student
